﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ARS.PublicTool.DataHandle
{
    public class ChoicesHelper
    {
        /// <summary>
        /// 从选择字符串里面获取值
        /// </summary>
        /// <param name="choices"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public string GetValueFromChoices(string choices,string value)
        {

            Dictionary<string, string> dict = GetListFromChoices(choices);
            return dict[value];
        }

        private Dictionary<string, string> _dict;
        public Dictionary<string, string> GetListFromChoices(string choices)
        {
            if (_dict == null)
            {
                _dict = new Dictionary<string, string>();
                string[] list = choices.Split(',');
                foreach (string str in list)
                {
                    string[] vt = str.Split('|');
                    _dict.Add(vt[0], vt[1]);
                }
            }
            return _dict;
        }

    }
}
